define(
		[ "PDUtilDir/util", "PDUtilDir/tool", "PDUtilDir/slidebar",
				"PDUtilDir/inputSelect",
				"PDUtilDir/fileupload/singleFileUpload", "Date", "DateCN",
				"css!DateCss", "PicView", "css!picViewCss",
				"css!AppPathDir/order/orderInfos/views/css/css" ],
		function(Util, Tool, Slidebar, inputSelect, MFU) {
			function updateSupportInit($scope, $compile) {
				return new updateSupport($scope, $compile);
			}
			function updateSupport($scope, $compile) {
				this.$scope = $scope;
				this.$compile = $compile;
				this.cache = {
					visitors: new Array()
				}
				this.entity = {
					orderNo: '001',
					groupName: '002',
					supplerOrgName: '003',
					shouldPayment: '004',
					actualPayment: '005',
					timeTableName: '006',
					payStatusName: '007',
					createTime: '008',
					modifyTime: '009',
					payment: '010',
					id: '011'
				};
			}
			updateSupport.fn = updateSupport.prototype;
			updateSupport.fn.digest = function() {
				this.$scope.$digest();
			};
			
//			updateSupport.fn.selectVisitor = function(id) {
//				var visitors = this.entity.visitors, len = visitors.length;
//				for(var i = 0; i < len; i++){
//					if(id == visitors[i].id){
//						this.cache.visitors.push(visitors[i]);
//						this.entity.visitors.splice(i,1);
////						this.digest();
//						break;
//					}
//				}
//			};
			
			updateSupport.fn.run = function(data) {
				var _this = this, data = undefined, dataArray = _this.$scope.grid.getAllData(), len = dataArray.length;
//				for (var i = 0; i < len; i++) {
//					if (id == data.id) {
//						data = dataArray[i];
//					}
//				}
//				_this.entity = $.extend(_this.entity, data);
//				var tmp_status = _this.$scope.cache.status;
//				len = tmp_status.length;
//				
//				if (tmp_status){
//					for (var i = 0; i < tmp_status.length; i++) {
//						if (tmp_status[i].dictCode == _this.entity.payStatus) {
//							_this.entity.payStatusName = tmp_status[i].dictName;
//						}
//					}
//				}
				this.slidebars = Slidebar({
					size : 'lg',
					url : getServer()
							+ "/static/app/order/buyOrderInfos/views/update.html",
//					close : true,
					$scope : this.$scope,
					$compile : this.$compile,
					afterLoad : function($Panel) {
						_this.initialization();
					}
				});
			};
			updateSupport.fn.initialization = function() {
				var _this = this;
				// 初始化支付类型下拉框
				inputSelect.dropCache();
				inputSelect({
					id : "paymentType",
					key : {
						id : "dictCode",
						name : "dictName",
						data : "data",
					},
					data : _this.$scope.cache.types,
					simpleData : true,
					searchAble : false,
					callback : function(id) {
						_this.entity.paymentType = id[0];
					}
				});
				//游客列表
			    $.ajax({
					url : getServer() + "/flea/hclv/visitor/order/listOrderVisitors.htmls",
					data: {
				    	model : _this.entity.orderNo,
				    },
					success : function(data) {
						_this.entity.visitors = data;
						_this.digest();
					}
				});
				_this.digest();
			};
			updateSupport.fn.save = function() {
				var _this = this;
				$.ajax({
					url : getServer() + "/flea/hclv/visitor/order/updateOrder.htmls",
					data : {
						'model' : JSON.stringify({
							id : _this.entity.id,
							orderNo : _this.entity.orderNo,
							totalAmount: this.entity.totalAmount,
							visitors: _this.cache.visitors,
							comment : _this.entity.comment
						})
					},
					success : function(data) {
                        if (data.status != 200) {
                            return;
                        }
						_this.$scope.grid.refresh();
						Util.alert('成功');
						_this.slidebars.close();
					}
				});
			};
			return updateSupportInit;
		});